/*
 * Copyright (C) 2009 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * SubscriptionStoreImpl.java
 * 
 * Created on Jan 5, 2009 at 10:58:05 PM
 */

package org.robcash.apps.messagepopup.vo.impl;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.robcash.apps.messagepopup.MessageException;
import org.robcash.apps.messagepopup.dataaccess.business.SubscriptionBD;
import org.robcash.apps.messagepopup.vo.Schedule;
import org.robcash.apps.messagepopup.vo.Subscription;
import org.robcash.apps.messagepopup.vo.SubscriptionStore;

/**
 * Default implementation of a subscription store
 * @author Rob
 */
public class SubscriptionStoreImpl implements SubscriptionStore {

    private URI location;
    private List<Schedule> schedules;
    private List<Subscription> subscriptions;
    private SubscriptionBD subscriptionService;

    public SubscriptionStoreImpl() {
        schedules = new ArrayList<Schedule>();
        subscriptions = new ArrayList<Subscription>();
    }

    /**
     * Get the location of the store
     * @return Store location
     */
    public URI getLocation() {
        // TODO Get rid of this method?
        return location;
    }

    /**
     * Set the location of the store
     * @param location Store location
     */
    public void setLocation(URI location) {
        // TODO Get rid of this method?
        this.location = location;
    }

    /**
     * Get the schedules
     * @return Schedules
     */
    public List<Schedule> getSchedules() {
        return schedules;
    }

    /**
     * Get the schedules
     * @param schedules Schedules
     */
    public void setSchedules(List<Schedule> schedules) {
        this.schedules = schedules;
    }

    /**
     * Set the subscription service
     * @param service Subscription store service
     */
    public void setSubscriptionService(SubscriptionBD service) {
        this.subscriptionService = service;
    }
    
    /**
     * Add a schedule
     * @param schedule Schedule to add
     */
    public void add(Schedule schedule) {
        schedules.add(schedule);
    }

    /**
     * Remove a schedule
     * @param schedule Schedule to remove
     */
    public void remove(Schedule schedule) {
        schedules.add(schedule);
    }

    /**
     * Clear all schedules and subscriptions
     */
    public void clear() {
        schedules.clear();
        subscriptions.clear();
    }

    /**
     * Get the subscriptions
     * @return Subscriptions
     */
    public List<Subscription> getSubscriptions() {
        return subscriptions;
    }

    /**
     * Set the subscriptions
     * @param subscriptions Subscriptions to set
     */
    public void setSubscriptions(List<Subscription> subscriptions) {
        this.subscriptions = subscriptions;
    }

    /**
     * Add a subscription
     * @param subscription Subscription to add
     */
    public void add(Subscription subscription) {
        subscriptions.add(subscription);
    }

    /**
     * Remove a subscription
     * @param subscription Subscription to remove
     */
    public void remove(Subscription subscription) {
        subscriptions.add(subscription);
    }

    /**
     * Save the subscription store
     * @throws MessageException Thrown if store cannot be saved
     */
    public void save() throws MessageException {
        subscriptionService.saveSubscriptionStore(this);
    }

}
